<!-- 工单处理过程记录编辑表单 -->
<template>
  <q-card style="width: 400px">
    <!-- 标题 -->
    <q-toolbar>
      <q-toolbar-title>{{ title }}</q-toolbar-title> <q-btn v-close-popup icon="close" round flat />
    </q-toolbar>
    <q-separator />

    <!-- 内容 -->
    <q-card-section>
      <q-form ref="formRef" class="row q-col-gutter-x-md">
        <q-input v-model.number="dto.orderId" label="工单id" :rules="[required]" class="col-12 col-sm-6"  type="number"  />
        <q-input v-model="dto.content" label="处理内容描述" :rules="[required]" class="col-12 col-sm-6"   />
      </q-form>
    </q-card-section>
    <q-separator />

    <!-- 操作 -->
    <q-card-actions v-if="!readonly">
      <q-checkbox v-model="closeAfterSave" label="保存后关闭" />
      <q-space />
      <q-btn v-close-popup>取消</q-btn>
      <q-btn color="primary" icon="save" :loading="loading" @click="handleSubmit">保存</q-btn>
    </q-card-actions>
  </q-card>
</template>

<script lang="ts" setup>
  import { required } from 'src/utils/validator';
  import { useCrudForm } from 'src/composables';

  import crudApi, { WorkProcessDto } from 'src/api/workorder/workprocess';

  // 属性和事件定义
  const props = defineProps({
    id: { type: [String, Number], default: undefined },
    title: { type: String, default: '工单处理过程记录表单' },
    readonly: { type: Boolean, default: false },
  });
  const emit = defineEmits(['close', 'after-save']);

  // 表单数据
  const initWorkProcess = {} as WorkProcessDto;
  const { formRef, dto, closeAfterSave, loading, handleSubmit } = useCrudForm<WorkProcessDto>(crudApi, initWorkProcess, props, emit);
</script>

<style lang="scss" scoped></style>
